package com.app.bimo.library_db.helper;


import com.app.bimo.library_db.AppData;
import com.app.bimo.library_db.dao.AppDataDao;
import com.app.bimo.library_db.dao.DaoSession;

public class AppDataHelper {

    private static volatile AppDataHelper sInstance;
    private static DaoSession daoSession;
    private static AppDataDao appDataDao;

    public static AppDataHelper getsInstance() {
        if (sInstance == null) {
            synchronized (AppDataHelper.class) {
                if (sInstance == null) {
                    sInstance = new AppDataHelper();
                    daoSession = DaoDbHelper.getInstance().getSession();
                    appDataDao = daoSession.getAppDataDao();
                }
            }
        }
        return sInstance;
    }

    /**
     * 保存用户
     *
     * @param appData
     */
    public void saveAppData(AppData appData) {
        appDataDao.deleteAll();
        appDataDao.insertInTx(appData);
        appDataDao.detachAll();
    }


    /**
     * 删除用户
     */
    public void removeAppData() {
        appDataDao.deleteAll();
    }


    /**
     * 查询用户信息
     *
     * @return
     */
    public AppData findAppData() {
        return appDataDao.queryBuilder().unique();
    }

}
